<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>将 Blob 转换为 Base64</title>
	</head>
	<body>
		<script>
			function downloadTx() {
				let link = document.createElement('a')
				link.download = 'hello.txt'

				let blob = new Blob(['Hello World!'], { type: 'text/plain' })

				let reader = new FileReader()
				reader.readAsDataURL(blob) // 将 Blob 转换为 Base64

				reader.onload = () => {
					link.href = reader.result
					link.click()
				}
			}

			setTimeout(downloadTx, 1000)
		</script>
	</body>
</html>
